package com.wuhongyu.controller;


import com.wuhongyu.common.MyCommon;
import com.wuhongyu.entity.Runoff;
import com.wuhongyu.service.RunoffService;
import com.wuhongyu.service.StatisticsService;
import com.wuhongyu.util.MyUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * 统计报表
 */
@Controller
@RequestMapping("/rept")
public class StatisticsController {

    @Autowired
    private RunoffService runoffService;
    @Autowired
    private StatisticsService statisticsService;

    /**
     * 客户流失分析,其实就是客户流失
     * @param model
     * @param request
     * @param runoff
     * @param number
     * @return
     */
    @RequestMapping("/lost")
    public String lost(Model model, HttpServletRequest request, Runoff runoff, Integer number) {
        runoff.setStatus(2);
        model.addAttribute("url",MyUtil.getUrl(request));
        model.addAttribute("page",runoffService.findAll(runoff,number));
        return "~rept/lost";
    }

    /**
     * 客户贡献分析
     * @param model
     * @param name
     * @param year
     * @return
     */
    @RequestMapping("/contr")
    public String contr(Model model, String name, String year){
        model.addAttribute("contrList",statisticsService.contr(name,year));
        return "~rept/contr";
    }

    /**
     * 客户构成分析
     * @param model
     * @param type
     * @return
     */
    @RequestMapping("/cons")
    public String cons(Model model, String type){
        if(StringUtils.isEmpty(type)){
            type=MyCommon.GRADE;
        }
        model.addAttribute("consList",statisticsService.cons(type));
        model.addAttribute("type",type);
        return "~rept/cons";
    }

    /**
     * 客户服务分析
     * @param model
     * @param year
     * @return
     */
    @RequestMapping("/server")
    public String server(Model model, String year){
        model.addAttribute("serList",statisticsService.server(year));
        return "~rept/ser";
    }
}